package operation;

import student.Student;
import student.StudentList;

import java.util.Scanner;

public class AddOperation implements IOperation{
    @Override
    public void work(StudentList list) {
        System.out.println("增加学生信息");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入姓名");
        String name = sc.nextLine();
        System.out.println("请输入性别");
        String sex = sc.nextLine();
        System.out.println("请输入身份证");
        String id = sc.nextLine();
        System.out.println("请输入电话");
        String tele = sc.nextLine();
        System.out.println("请输入学号");
        String studentId = sc.next();
        System.out.println("请输入年龄");
        int age = sc.nextInt();
        // new Student的对象 来存放 上面刚录入的信息
        Student stu = new Student(studentId,name,age,sex,id,tele);
        int sz = list.size();
        for(int i = 0; i < sz; i++){
            Student stu1 = list.get(i);
            if(stu1.getStudentId().equals(stu.getStudentId())){
                System.out.println("已有该学生，无法继续加入");
                return;
            }
        }

        list.add(stu);
        System.out.println("插入成功！");
    }
}
